<template>
	<view>
		<uni-popup ref="popupcheck" type="bottom">
			<view style="background: #fff;">
				<view
					style="display: flex;background: #fff;padding: 10px;width: calc(100% - 10px);box-sizing: border-box;margin-left: 5px;justify-content: space-between;">
					<view style="color: #000;font-size: 20px;float: left;" @click="close">取消</view>
					<view style="color: green;font-size: 20px;float: right;" @click="submit">确认</view>
				</view>
				<uni-search-bar @confirm="search" v-model="searchValue" @clear="hobby = data"
					@cancel="hobby = data"></uni-search-bar>
				<uni-data-checkbox showType="parentSon" selectedColor="#d1100a" :map="{text:'NickName',value:'Id'}"
					emptyText="暂无数据" mode="tag" multiple v-model="checkbox" :localdata="hobby" @change="change">
				</uni-data-checkbox>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	//不想双向绑定了
	export default {
		props: {
			parentObj: {
				type: Object
			}
		},
		data() {
			return {
				checkboxRows: [],
				checkbox: [],
				hobby: [],
				data: [],
				searchValue: '',
				isProjectId: ""
			}
		},
		methods: {
			// 搜索
			search(e) {
				let arr = []
				this.data.forEach(item => {
					let newStr = item.NickName + item.Name + item.Phone
					item.newStr = newStr
					console.log('循环', item, item.NickName, item.Name, item.Phone, '-----    ' + item.newStr)
					if (item.newStr.indexOf(e.value) != -1) {
						arr.push(item)
					}
				})
				this.hobby = arr
			},
			open(data) {
				this.isProjectId = data
				this.searchValue = ''
				this.getDataList()
				this.$refs.popupcheck.open()
			},
			close() {
				this.searchValue = ''
				this.$refs.popupcheck.close()
				this.checkboxRows = []
				this.checkbox = []
			},
			change(e) {
				this.checkboxRows = e.detail.data
			},
			submit() {
				this.$emit('subclickRow', this.checkboxRows)
				this.$emit('subclickId', this.checkbox)
				this.$refs.popupcheck.close()
				this.checkboxRows = []
				this.checkbox = []
			},
			getDataList() {
				console.log('打印项目id', this.pid, this.isProjectId)
				let Search = {}
				let url = ""
				if (this.isProjectId === 'noProjectID') {
					url = "Base_Mail/Base_MailList/GetDataList"
					Search = {
						SortField: "Initial",
						SortType: "asc",
					}
				} else {
					url = "Base_Mail/Base_MailList/GetDataMailList"
					Search = {
						SortField: "Initial",
						SortType: "asc",
						Search: {
							ProjectId: this.parentObj.ProjectId
						}
					}
				}
				this.$http(url, Search)
					.then((res) => {
						if (res.Success) {
							this.hobby = res.Data.filter(item => (item.MailUserId != uni.getStorageSync('userInfo')
								.Id) && (!item.IsLogout))
							this.data = res.Data.filter(item => (item.MailUserId != uni.getStorageSync('userInfo')
								.Id) && (!item.IsLogout))
						}
						console.log('获取添加人员', this.hobby);
					});
			}
		}
	}
</script>

<style scoped lang="scss">
	/deep/.checklist-group {
		display: block !important;
		width: 100%;
		height: 40vh;
		padding: 0px 10px 10px 10px;

		box-sizing: border-box;
		text-align: center;
		overflow-y: scroll;
	}

	/deep/.checklist-box {
		display: block !important;
		margin: 5px !important;
	}

	/deep/.checklist-content {

		display: block !important;
	}
</style>